package com.example.demo.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.common.IdParam;
import com.example.demo.domain.entity.ProblemCategory;
import com.example.demo.domain.entity.VojProblemCategories;
import com.example.demo.dto.ProblemCategoryDto;
import com.example.demo.param.voj.VojCategorySaveParam;
import com.example.demo.service.VojProblemCategoriesService;
import com.example.demo.mapper.VojProblemCategoriesMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
* @author 00774904
* @description 针对表【voj_problem_categories】的数据库操作Service实现
* @createDate 2023-12-08 17:29:32
*/
@Service
public class VojProblemCategoriesServiceImpl extends ServiceImpl<VojProblemCategoriesMapper, VojProblemCategories>
implements VojProblemCategoriesService{

    @Resource
    private VojProblemCategoriesMapper vojProblemCategoriesMapper;
    @Override
    public List<ProblemCategoryDto> getAll() {
        List<VojProblemCategories> list = vojProblemCategoriesMapper.selectList(new QueryWrapper<>());
        List<ProblemCategoryDto> result = BeanUtil.copyToList(list, ProblemCategoryDto.class);
        return result;
    }

    @Override
    public void save(VojCategorySaveParam param) {
        VojProblemCategories entity = BeanUtil.copyProperties(param, VojProblemCategories.class);
        if (param.getId() == null){
            // 新增
            vojProblemCategoriesMapper.insert(entity);
        }else{
            // 保存
            vojProblemCategoriesMapper.updateById(entity);
        }
    }

    @Override
    public void delete(Long id) {
        vojProblemCategoriesMapper.deleteById(id);
    }
}
